package com.tarena.lbs.coupon.dao.repository.impl;

import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.coupon.api.pojo.param.UserCouponsParam;
import com.tarena.lbs.coupon.dao.mapper.CouponMapper;
import com.tarena.lbs.coupon.dao.repository.CouponRepository;
import com.tarena.lbs.coupon.pojo.param.CouponParam;
import com.tarena.lbs.coupon.pojo.query.UserCouponCodeQuery;
import com.tarena.lbs.coupon.pojo.query.UserCouponQuery;
import com.tarena.lbs.coupon.pojo.vo.CouponVO;
import com.tarena.lbs.coupon.pojo.vo.UserCouponsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class CouponRepositoryImpl implements CouponRepository {
    @Autowired
    private CouponMapper couponMapper;
    @Autowired
    private StockRepositoryImpl stockRepository;
    @Override
    public CouponVO detail(Integer id) { return couponMapper.detail(id);
    }
    @Override
    public PageResult<CouponVO> pageList() {
        return couponMapper.pageList();
    }
    @Override
    public void addCoupon(CouponParam couponParam) {
        couponMapper.addCoupon(couponParam);
    }
    @Override
    public PageResult<UserCouponsVO> receiveList(UserCouponQuery couponQuery) {
        return couponMapper.receiveList(couponQuery);
    }
    @Override
    public UserCouponsVO receiveDetail(UserCouponCodeQuery query) {
        return couponMapper.receiveDetail(query);
    }

    @Override
    public void receiveCoupon(UserCouponsParam param) {
        couponMapper.receiveCoupon(param);
    }
    @Override
    public void addStock(Integer couponId, Object stockParam) {
        // 假设 stockParam 实际应为 Integer 类型
        if (stockParam instanceof Integer) {
            stockRepository.addStock(couponId, (Integer) stockParam);
        } else {
            throw new IllegalArgumentException("stockParam must be of type Integer");
        }
    }
    @Override
    public void updateStock(Integer couponId, Integer stock) {
        stockRepository.updateStock(couponId, stock);
    }

}
